package cn.edu.ctbu.sbadmin.grade.controller;


import cn.edu.ctbu.sbadmin.common.controller.BaseController;
import cn.edu.ctbu.sbadmin.common.domain.TreeDO;
import cn.edu.ctbu.sbadmin.common.utils.StringUtils;
import cn.edu.ctbu.sbadmin.common.utils.UserType;
import cn.edu.ctbu.sbadmin.grade.domain.DimGraduationProjectDO;
import cn.edu.ctbu.sbadmin.grade.domain.StudentDO;
import cn.edu.ctbu.sbadmin.grade.service.DimGraduationProjectService;
import cn.edu.ctbu.sbadmin.grade.service.StudentService;
import cn.edu.ctbu.sbadmin.system.domain.MenuDO;
import cn.edu.ctbu.sbadmin.system.service.MenuService;
import cn.edu.ctbu.sbadmin.system.service.UserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping
public class StudentController extends BaseController {

    @Autowired
    MenuService menuService;

    @Autowired
    UserService userService;

    @Autowired
    StudentService studentService;

    @Autowired
    DimGraduationProjectService dimGraduationProjectService;


    @RequestMapping("/student/index")
    @RequiresPermissions("grade:student:index")
    public  String Index(Model model){

        if (getUser().getUserType() == UserType.Student()){

            List<DimGraduationProjectDO> dimGraduationProjectDOS = dimGraduationProjectService.getAll();

            List<TreeDO<MenuDO>> menus = menuService.listMenuTreeByRoleName(UserType.Student());
            model.addAttribute("menus",menus);

            StudentDO studentDO = studentService.getById(getUser().getId());

            model.addAttribute("name",studentDO.getName());
            model.addAttribute("eamil","");
            model.addAttribute("mobile","");
            model.addAttribute("dimGraduationProjectDOS",dimGraduationProjectDOS);
            model.addAttribute("currentNum",2022);

            if (!StringUtils.isEmpty(studentDO.getAvatar())){
                model.addAttribute("picUrl",studentDO.getAvatar());
            }else {
                model.addAttribute("picUrl","/img/profile-photos/1.png");
            }
        }
        model.addAttribute("username",getUser().getUsername());

        return "grade/student/index";
    }


    /**
    * {comments}管理的基础页面
    * @return
    */
    @RequestMapping("/grade/student/list")
    @RequiresPermissions("grade:student:list")
    public  String list(){
        return "grade/student/list";
    }

    /**
     * {comments}管理的编辑及新增页面
     * @return
     */
    @RequestMapping("/grade/student/edit")
    @RequiresPermissions("grade:student:edit")
    public  String edit(){
        return "grade/student/edit";
    }

}
